//
//  TestAfnetHttp.m
//  TestAfnetwork
//
//  Created by xujingjing on 16/6/15.
//  Copyright © 2016年 xujingjing. All rights reserved.
//

#import "TestAfnetHttp.h"


@implementation TestAfnetHttp


+(void)postWithUrl:(NSString *)urlstr paramters:(NSDictionary *)paramters success:(MyCallback)success failed:(void(^)(id faile))failed{

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer.timeoutInterval = 5;
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [manager.requestSerializer setValue:API_KEY forHTTPHeaderField:@"apikey"];
   // manager.responseSerializer = [AFJSONResponseSerializer serializer];//声明返回的结果是json类型
   
    //set cachePolicy
    manager.requestSerializer.cachePolicy = NSURLRequestReturnCacheDataElseLoad;

    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javescript",@"text/plain",@"text/html", nil];
        
    [manager POST:urlstr parameters:paramters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       
        success(responseObject);

   } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       
       NSLog(@"————————————————————》error%@",error);

   }];
    
    
}

@end
